<template>
	<view class="content">
		<template v-for="(item, index) of data">
			<view :key="index" class="webList" :id="item.name">
				<view class="title">
					<text class="uicon-tags u-iconfont"></text>
					<text>{{ item.name }}</text>
				</view>

				<view class="webItems">
					<template v-for="web of item.web">
						<m-link :url="web.url" :tooltip="web.url" :key="web.title" class="webItem">
							<image :src="web.logo"></image>
							<view class="text">
								<view class="name">{{ web.title }}</view>
								<view class="desc">{{ web.desc }}</view>
							</view>
						</m-link>
					</template>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
import data from '@/static/data.js';

export default {
	created() {
		this.data = this.changeData(data);
	},
	data() {
		return {
			data: []
		};
	},
	methods: {
		changeData(webData) {
			let arr = [];
			for (let web of webData) {
				if (web.children) {
					let arrAppend = this.changeData(web.children);
					arr.push(...arrAppend);
				} else {
					arr.push(web);
				}
			}

			return arr;
		}
	}
};
</script>

<style lang="scss" scoped>
.content {
	background-color: #f9f9f9;
	padding-bottom: 20px;

	@media (min-width: 768px) {
		.webItems {
			display: flex;
			flex-wrap: wrap;

			.webItem {
				width: 22%;
				margin-right: 3%;
			}
		}
	}

	.webList {
		padding: 20px 20px 0 20px;

		.title {
			display: flex;
			align-items: center;

			> text {
				color: #828383;
				font-size: 22px;
				+ text {
					font-size: 17px;
					margin-left: 10px;
				}
			}
		}

		.webItems {
			.webItem:hover {
				cursor: pointer;
				transform: translateY(-6px);
				box-shadow: 0 26px 40px -24px rgba(0, 36, 100, 0.3);
				transition: all 0.3s ease;
			}

			.webItem {
				background-color: #ffffff;
				margin-top: 20px;
				display: flex;
				align-items: center;
				padding: 15px;
				border-radius: 4px;
				border: 1px solid #e4ecf3;

				image {
					width: 40px;
					height: 40px;
					flex-shrink: 0;
				}

				.text {
					margin-left: 16px;
					flex: 1;
					font-size: 13px;
					line-height: 1.5;

					.name {
						font-weight: bold;

						word-break: break-all;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
					}

					.desc {
						color: #979898;

						word-break: break-all;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
					}
				}
			}
		}
	}
}
</style>
